package com.cxs.controller;

import com.cxs.dto.LoginDTO;
import com.cxs.vo.LoginVO;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

/**
 * @Project: spring-boot-remote-debug-demo
 * @Author: cxs2014501@163.com
 * @Create: 2023/2/13 13:40
 * @Description:
 **/
@RestController
@RequestMapping("/debug")
public class DebugController {

    private static final String ACCOUNT = "admin";
    private static final String PWD = "admin1234";

    @PostMapping("/login")
    public Map<String, Object> login(@RequestBody LoginDTO dto){
        Map<String, Object> map = new HashMap<>();
        if (ACCOUNT.equals(dto.getUsername()) && PWD.equals(dto.getPassword())) {
            LoginVO vo = new LoginVO();
            BeanUtils.copyProperties(dto, vo);
            vo.setLoginTime(LocalDateTime.now());
            map.put("data", vo);
            map.put("msg", "登陆成功");
        } else {
            map.put("msg", "登陆失败,用户名或密码错误");
        }
        return map;
    }
}
